package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.IndustryCache;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserInfoHelper;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 15 付费类型
 */
@UserAttrSupplier(attrField = "ORD10236")
@Service
public class PayModeSupplier extends AbstractUserAttrSupplier {

    @Override
    public String getValue() {
        String payModeValue = KiteMapUtils.getString(userInfoContext.getUserInfo(), "PAY_MODE");
        if (KiteStringUtils.isEmpty(payModeValue)) {
            payModeValue = AttrValueCache.getAttrValue("2020111105", payModeValue).getAttrValueName();
        }
        return payModeValue;
    }

    @Override
    public String getValueDesc() {
        String payModeValue = getValue();
        return Optional.ofNullable(AttrValueCache.getAttrValue("2020111105", payModeValue))
            .map(AttrValue::getAttrValueName).orElse(payModeValue);
    }
}
